package com.chenbei.erp.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenbei.common.domain.BaseEntity;
import com.chenbei.erp.domain.InventoryLog;
import com.chenbei.erp.vo.req.InventoryLogReq;
import com.chenbei.erp.mapper.InventoryLogMapper;
import com.chenbei.erp.service.IInventoryLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class InventoryLogService extends ServiceImpl<InventoryLogMapper, InventoryLog> implements IInventoryLogService {

    @Override
    public void add(InventoryLog InventoryLog) {
        save(InventoryLog);
    }

    @Override
    public Page<InventoryLog> pageList(InventoryLogReq InventoryLogReq) {
        LambdaQueryWrapper<InventoryLog> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(InventoryLog::getId);
        if (InventoryLogReq.getInventoryId() != null && InventoryLogReq.getInventoryId() > 0) {
            lambdaQueryWrapper.eq(InventoryLog::getInventoryId, InventoryLogReq.getInventoryId());
        }
        if (StrUtil.isNotBlank(InventoryLogReq.getStartDate()) && StrUtil.isNotBlank(InventoryLogReq.getEndDate())) {
            lambdaQueryWrapper.between(BaseEntity::getCreateTime, InventoryLogReq.getStartDate() + " 00:00:00", InventoryLogReq.getEndDate() + " 23:59:59");
        }
        Page<InventoryLog> pageConfig = new Page<>(InventoryLogReq.getPageNum(), InventoryLogReq.getPageSize());
        return page(pageConfig, lambdaQueryWrapper);
    }
}
